package br.xraylol.client;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Component;

import br.xraylol.bean.riot.MasteryPageBean;
import br.xraylol.bean.riot.SummonerBean;
import br.xraylol.constant.ServiceType;
import br.xraylol.custom.list.RunePageList;

@Component
public class SummonerClient extends GenericClient {
	
	public SummonerClient() {
		super(ServiceType.SUMMONER);
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, SummonerBean> findSummonersByName(List<String> summonersName) {
		return findAll("/by-name/" + concatSummonersName(summonersName), HashMap.class, false);
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, SummonerBean> findSummonersById(List<Long> summonersId) {
		return findAll("/" + concatSummonersId(summonersId), HashMap.class, false);
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, MasteryPageBean> findSummonersMasteries(List<Long> summonersId) {
		return findAll("/" + concatSummonersId(summonersId) + "/masteries", HashMap.class, false);
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, String> findSummonersName(List<Long> summonersId) {
		return findAll("/" + concatSummonersId(summonersId) + "/name", HashMap.class, false);
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, RunePageList> findSummonersRunes(List<Long> summonersId) {
		return findAll("/" + concatSummonersId(summonersId) + "/runes", HashMap.class, false);
	}
	
	private String concatSummonersId(List<Long> summonersId) {
		String summoners = "";
		for (Long summonerId : summonersId) {
			summoners += summonerId + ",";
		}
		
		return summoners;
	}
	
	private String concatSummonersName(List<String> summonersName) {
		String summoners = "";
		for (String summonerName : summonersName) {
			summoners += summonerName + ",";
		}
		
		return summoners;
	}
}
